package com.lam.common.config;

import java.nio.charset.StandardCharsets;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import com.lam.common.model.AliDaYu;
import com.lam.common.model.LocalAttachment;
import com.lam.common.model.Qiniu;
import com.lam.common.utils.SpringUtils;
import com.lam.common.utils.StringUtils;

/**
 * 读取项目相关配置
 * 
 * @author lam
 */
@Component
@ConfigurationProperties(prefix = "lam")
public class AppBaseConfig {
	
	private static final String DEF_AUTH_TOKEN_SIGN_KEY = "lamyz-0417668800";
	private static final String DEF_AUTH_PASSWORD_SIGN_KEY = "lamyz-0417668822";
	
	/** 项目名称 */
	private String name;
	/** Java代码工程名称 */
	private String javaProjectName;
	/** Java代码启动器入口工程 */
	private String javaStarterName;
	/** ui工程名 */
	private String uiProjectName;

	/** 版本 */
	private String version;

	/** 版权年份 */
	private String copyrightYear;
	
	/** 用于加密token的aes签名的key，16位 */
	private String authTokenSignKey;
	
	/** 用于加密password的aes签名的key，16位 */
	private String authPasswordSignKey;

	/** 公共目录,用于存放上传和下载文件产生的临时文件等 */
	private String commonPath;
	
	/** 文件上传方式 1.上传到本地 2.上传到七牛云 */
	private Integer uploadType;
	
	/** 上传文件到本地时的存储信息 */
	private LocalAttachment localAttachment;
	
	/** 七牛云的配置信息 */
	private Qiniu qiniu;
	
	/** 阿里大于短信平台 */
	private AliDaYu aliDaYu;
	
	private static AppBaseConfig instance;
	
	public static AppBaseConfig me() {
		if(instance == null) {
			instance = SpringUtils.getBean(AppBaseConfig.class);
		}
		return instance;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getVersion() {
		return version;
	}

	public void setVersion(String version) {
		this.version = version;
	}

	public String getCopyrightYear() {
		return copyrightYear;
	}

	public void setCopyrightYear(String copyrightYear) {
		this.copyrightYear = copyrightYear;
	}

	public String getCommonPath() {
		return commonPath;
	}

	public void setCommonPath(String profile) {
		commonPath = profile;
	}

	/**
	 * 获取头像上传路径
	 */
	public String getAvatarPath() {
		return getCommonPath() + "/avatar/";
	}

	/**
	 * 获取下载路径
	 */
	public String getDownloadTmpPath() {
		return getCommonPath() + "/downloadTmp/";
	}

	/**
	 * 获取上传临时路径
	 */
	public String getUploadTmpPath() {
		return getCommonPath() + "/uploadTmp/";
	}

	public String getUiProjectName() {
		return uiProjectName;
	}

	public void setUiProjectName(String uiProjectName) {
		this.uiProjectName = uiProjectName;
	}

	public String getJavaProjectName() {
		return javaProjectName;
	}

	public void setJavaProjectName(String javaProjectName) {
		this.javaProjectName = javaProjectName;
	}

	public String getJavaStarterName() {
		return javaStarterName;
	}

	public void setJavaStarterName(String javaStarterName) {
		this.javaStarterName = javaStarterName;
	}

	public Qiniu getQiniu() {
		return qiniu;
	}

	public void setQiniu(Qiniu qiniu) {
		this.qiniu = qiniu;
	}

	public Integer getUploadType() {
		return uploadType;
	}

	public void setUploadType(Integer uploadType) {
		this.uploadType = uploadType;
	}

	public LocalAttachment getLocalAttachment() {
		return localAttachment;
	}

	public void setLocalAttachment(LocalAttachment localAttachment) {
		this.localAttachment = localAttachment;
	}

	public AliDaYu getAliDaYu() {
		return aliDaYu;
	}

	public void setAliDaYu(AliDaYu aliDaYu) {
		this.aliDaYu = aliDaYu;
	}

	public String getAuthTokenSignKey() {
		return StringUtils.isBlank(authTokenSignKey)? DEF_AUTH_TOKEN_SIGN_KEY : authTokenSignKey;
	}
	
	public byte[] getAuthTokenSignKeyByte() {
		return getAuthTokenSignKey().getBytes(StandardCharsets.UTF_8);
	}

	public void setAuthTokenSignKey(String authTokenSignKey) {
		this.authTokenSignKey = authTokenSignKey;
	}

	public String getAuthPasswordSignKey() {
		return StringUtils.isBlank(authPasswordSignKey)? DEF_AUTH_PASSWORD_SIGN_KEY : authPasswordSignKey;
	}
	
	public byte[] getAuthPasswordSignKeyByte() {
		return getAuthPasswordSignKey().getBytes(StandardCharsets.UTF_8);
	}

	public void setAuthPasswordSignKey(String authPasswordSignKey) {
		this.authPasswordSignKey = authPasswordSignKey;
	}

}
